<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html ng-app="wechatQyLogin">
  <head>
    <base href="<%=basePath%>">
    <title>微信企业号自动登录</title>
  	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="1">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="<c:url value='/plugin/ionic/css/style.css'/>" rel="stylesheet">    
<link href="<c:url value='/plugin/ionic/css/ionic.css'/>" rel="stylesheet">
<script src="<c:url value='/plugin/ionic/js/ionic.bundle.js'/>"></script>
<script src="<c:url value='/plugin/angular/angular.js'/>"></script>

  
<style type="text/css">
.loading {
   margin-top: 10px !important;
   text-align: center;
   margin-bottom: 10px !important;
}

.spinner svg {
  width: 19% !important;
  height: 85px !important;
}
</style>
   
   <script type="text/javascript">
     angular.module('wechatQyLogin', ['ionic']).controller('wechatQyLoginController', function($scope) { 
       	$scope.showLoading=true;
    	$scope.getElementsByClassName=function(className) {
    		    var all=document.all?document.all:document.getElementsByTagName('*');
    		    var elements = new Array();
    		    for (var e=0;e<all.length;e++) {
    		     if (all[e].className == className) {
    		       elements[elements.length] = all[e];
    		       break ;
    		      }
    		    }
    		    return elements;
         };
       
         $scope.initPage=function(){
        	  var hasError=$scope.getElementsByClassName("red").length>0;
              if(hasError==true){
              	$scope.showLoading=false;
              	return;
              }
              var wechatAuthCode=document.getElementById("wechatQyAuthCode").value;
           	  if(wechatAuthCode==""&&hasError==false){//没有错误信息
             	    window.location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${wechatLoginURL}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect';
              }else if(wechatAuthCode!=""&&hasError==false){
              	    document.getElementById("formLogin").submit();
           	  }
         };
          $scope.initPage();
     });
    
    </script>
    
     </head>
 <body  ng-controller="wechatQyLoginController">
  <p  class="loading"  ng-show="showLoading">
  <ion-spinner icon="lines"  class="spinner-calm"></ion-spinner>
   <br> 登录中....
  </p>
  

   <form action="<%=basePath%>login" id="formLogin" method="post" >
          <c:if test="${sessionScope.SPRING_SECURITY_LAST_EXCEPTION=='org.springframework.security.authentication.AuthenticationServiceException'}">
                      <font color="red">用户名不存在</font>
          </c:if>
          <c:if test="${sessionScope.SPRING_SECURITY_LAST_EXCEPTION=='org.springframework.security.authentication.BadCredentialsException: Bad credentials'}">
                      <font color="red"> 密码错误</font>
         </c:if>
         <c:if test="${sessionScope.SPRING_SECURITY_LAST_EXCEPTION=='org.springframework.security.authentication.LockedException: User account is locked'}">
                       <font color="red">用户被锁定，请联系管理员解锁。</font>
         </c:if>
         <c:if test="${sessionScope.SPRING_SECURITY_LAST_EXCEPTION=='org.springframework.security.web.authentication.session.SessionAuthenticationException: Maximum sessions of 1 for this principal exceeded'}">
                      <font color="red"> 该用户已在别处登录，请先退出<br/>后再登录或联系管理员<br/>踢除已登录账户。</font>
         </c:if>
 
            <input name="username"     type="hidden">
            <input name="password"     type="hidden">
            <input name="deviceType"  value="mobile"    type="hidden">
            <input name="wechatQyAuthCode" id="wechatQyAuthCode" value="${wechatQyAuthCode}" type="hidden">
       
</form>
  
 </body>
</html>
